home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13681 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.6 KB

  1. Path: nnrp.info.ucla.edu!jmartin
  2. From: jmartin@cs.ucla.edu (Jay Martin)
  3. Newsgroups: comp.lang.eiffel,comp.lang.c,comp.lang.c++,comp.object,comp.software-eng
  4. Subject: Re: Portability of code & skills (Beware of "C" Hackers etc)
  5. Date: 26 Mar 1996 21:10:02 GMT
  6. Organization: University of California, Los Angeles
  7. Message-ID: <4j9mfa$ibe@saba.info.ucla.edu>
  8. References: <31494D29.4D4B@dmu.ac.uk> <DooBwC.8C0@world.std.com> <65O34-3-3RB@herold.franken.de> <4j8177$18ma@saba.info.ucla.edu> <4j921v$b5q@bug.rahul.net>
  9. NNTP-Posting-Host: may.cs.ucla.edu
  10. X-Newsreader: NN version 6.5.0.b3.0 #9 (NOV)
  11.  
  12. RjB <onomoto@rahul.net> writes:
  13.  
  14. >In article <4j8177$18ma@saba.info.ucla.edu>,
  15. >Jay Martin <jmartin@cs.ucla.edu> wrote:
  16. >>
  17. >>>  function CountThem (l: List): integer;
  18. >>>  var Count: integer
  19. >>>    procedure CountOne (e: ListElement);
  20. >>>    begin
  21. >>>      if <some condition on e fulfilled> then begin
  22. >>>        Count := Count + 1;
  23. >>>      end;
  24. >>>    end;
  25. >>>  begin
  26. >>>    ApplyOnList (l, CountOne); (* !!!! *)
  27. >>>    CountThem := Count
  28. >>>  end;
  29. >>
  30. >>
  31. >>This is what I call side-effects on a global variable (or variable of
  32. >>a larger scope).  Its not what I call good programming practice.  In
  33. >>fact, I see nested procedures as implemented in algol block languages
  34. >>(automatic importation of variables from larger scopes) as another
  35. >>stupid idea of CS.  
  36.  
  37. >    Hardly:  If CountThem is part of the published interface, then
  38. >how Count is used is immaterial. 
  39.  
  40. Excluding dinky cases like the above, it does matter how functions
  41. are constructed even if it is part of a "published interface".
  42.  
  43. By looking at :
  44.    ApplyOnList (l, CountOne); (* !!!! *)
  45.  
  46. You have no idea that you have smashed variables in the local context.
  47. (Count).  As code gets larger and more complex this trick becomes
  48. counter productive.
  49.  
  50. >    The point that you appear to be missing is that procedures and
  51. >functions are treated in a first-class manner, which is both powerful
  52. >and easy to understand. 
  53.  
  54. I am not convinced of either.  
  55.  
  56. >Compare this to how C/C++ uses pointers to
  57. >functions: it requires a great deal of work to get by the compiler,
  58. >and introduces a tremendous succeptibility to error.  And when the
  59. >pointers do get munged, finding the bug isn't necessarily easy.
  60.  
  61. Nonsense. In the cases like the above you would not use pointers
  62. but references to functions, which do not have the pointer problems.
  63.  
  64. So what it really comes down to is allowing/promoting side-effects on
  65. the existing scope.  The solution is in someway to pass the necessary
  66. variables making their use explicit to the interface of CountOne and
  67. the call of ApplyOnList. Like:
  68.  
  69. ApplyOnList(l, CountOne, Count);
  70.  
  71. Jay
  72.